

import axios from 'axios';
import { message } from 'antd';
 export default function ajax(url,data={},type='GET'){
    return new Promise((resolve,reject)=>{
        let promise
        if (type == 'GET') {
            let dataStr = ''; //数据拼接字符串
            Object.keys(data).forEach(key => {
                dataStr += key + '=' + data[key] + '&';
            })
    
            if (dataStr !== '') {
                dataStr = dataStr.substr(0, dataStr.lastIndexOf('&'));
                url = url + '?' + dataStr;
            }
            //发送get请求
            promise=axios.get(url)
        }else {
            //发送post请求
            promise=axios.get(url,data)
                
        }
        promise.then(res=>{

        }).catch(error=>{
            message.info('出错了');
        })
    
    })

 }

